<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>CPU信息</span>
                    </div>
                    <el-table :data="cpuList" height="223" border style="width: 100%">
                        <el-table-column prop="name" label="属性">
                        </el-table-column>
                        <el-table-column prop="value" label="值">
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>内存信息</span>
                    </div>
                    <el-table :data="memlist" height="223" border style="width: 100%">
                        <el-table-column prop="name" label="属性">
                        </el-table-column>
                        <el-table-column prop="value" label="内存">
                        </el-table-column>

                    </el-table>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>JAVA虚拟机信息</span>
                    </div>
                    <el-descriptions :column="2" border>
                        <el-descriptions-item>
                            <template slot="label">
                                Jvm名称
                            </template>
                           {{ jvmInfo.jdkName }}
                        </el-descriptions-item>
                        <el-descriptions-item>
                            <template slot="label">
                                Java版本
                            </template>
                            {{ jvmInfo.jdkVersion }}
                        </el-descriptions-item>
                        <el-descriptions-item>
                            <template slot="label">
                                启动时间
                            </template>
                            {{ jvmInfo.startTime }}
                        </el-descriptions-item>
                        <el-descriptions-item>
                            <template slot="label">
                                运行时长
                            </template>
                            {{ jvmInfo.runTime }}
                        </el-descriptions-item>
                        <el-descriptions-item :span="2">
                            <template slot="label">
                                安装路径
                            </template>
                           {{ jvmInfo.jdkHome }}
                        </el-descriptions-item>

                        <!-- <el-descriptions-item>
                            <template slot="label">
                                项目路径
                            </template>
                            /data2/BES/data/dacp/instances/archive/bin
                        </el-descriptions-item> -->
                    </el-descriptions>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>服务器信息</span>
                    </div>
                    <el-descriptions :column="2" border>
                        <el-descriptions-item label="服务器名称">{{ sysInfo.computerName }}</el-descriptions-item>
                        <el-descriptions-item label="操作系统">{{ sysInfo.osName }}</el-descriptions-item>
                        <el-descriptions-item label="服务器IP">{{ sysInfo.computerIp }}</el-descriptions-item>
                        <el-descriptions-item label="系统架构">{{  sysInfo.osArch  }}</el-descriptions-item>
                    </el-descriptions>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>磁盘信息</span>
                    </div>
                    <el-table :data="sysFilesList" height="220" border style="width: 100%">
                        <el-table-column prop="dirName" label="盘符路径">
                        </el-table-column>
                        <el-table-column prop="sysTypeName" label="文件系统">
                        </el-table-column>
                        <el-table-column prop="total" label="总大小">
                        </el-table-column>
                        <el-table-column prop="free" label="可用大小">
                        </el-table-column>
                        <el-table-column prop="used" label="已用大小">
                        </el-table-column>
                        <el-table-column prop='usage' label="已用百分比" width="100px">
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { monitorserver } from "@/api/homePage";
import { formatDate } from "@/utils/index.js"
export default {
    data() {
        return {

            cpuList: [],
            sysFilesList: [],
            memlist: [],
            sysInfo: "",
            jvmInfo:""
        }
    },
    created() {
        var that = this;
        that.monitorServerPOST();
    },
    methods: {
        //磁盘信息
        monitorServerPOST() {
            monitorserver().then(response => {

                var responseData=response.data
                var str =responseData.cpu.user + ""
                var index = str.indexOf('%');
                if (index != -1) {
                    var result = str.substring(0, index);
                }
             
                this.cpuList = [
                    {
                        "name": "核心数",
                        "value": responseData.cpu.cpuNum
                    },
                    {
                        "name": "用户使用率",
                        "value": responseData.cpu.user
                    },
                    {
                        "name": "系统使用率",
                        "value": responseData.cpu.cSys
                    },
                    {
                        "name": "当前空闲率",
                        "value": (100 - result) + '%'
                    },
                ]
                this.memlist = [
                    {
                        "name": "总内存",
                        "value": responseData.mem.total
                    }, {
                        "name": "已用内存",
                        "value": responseData.mem.used
                    }, {
                        "name": "剩余内存",
                        "value": responseData.mem.free
                    }, {
                        "name": "使用率",
                        "value":responseData.mem.usageRate
                    }
                ]


                this.sysInfo =responseData.sys;
              
              this.sysFilesList = responseData.sysFiles;

              responseData.jvm.startTime=  formatDate(responseData.jvm.startTime);
              this.jvmInfo=responseData.jvm;
              for (var i in responseData.sysFiles) {
                responseData.sysFiles[i].usage = responseData.sysFiles[i].usage + "%"
              }


            })
        },
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    padding: 2vh !important;
}

.el-row {
    margin-bottom: 20px;

    &:last-child {
        margin-bottom: 0;
    }
}
</style>